//
//  MLCircleInfoMainPageViewModel.m
//  MiaoCircle
//
//  Created by 许正荣 on 2018/4/18.
//  Copyright © 2018年 acgera. All rights reserved.
//

#import "MLCircleInfoMainPageViewModel.h"
#import "MHSettingCircleViewModel.h"
#import "MHSearchViewModel.h"
@interface MLCircleInfoMainPageViewModel()
@property (nonatomic, readwrite, strong) RACCommand *nextCommand;


@end

@implementation MLCircleInfoMainPageViewModel

- (instancetype)initWithServices:(id<MHViewModelServices>)services params:(NSDictionary *)params{
    if (self = [super initWithServices:services params:params]) {
        self.circleInfo = params[MHViewModelUtilKey];
        self.circielId = [params[MHViewModelIDKey] integerValue];
        self.fromeCreate = [params[@"MHViewModelFromCreate"] integerValue];
    }
    return self;
}

-(void)initialize
{
    [super initialize];
//    self.rightImageStr = @"circle_setting";
    @weakify(self);
    self.translucentNavigationBar = YES;
    //
    self.interactivePopDisabled = YES;
    self.nextCommand =[[RACCommand alloc] initWithSignalBlock:^RACSignal *(NSIndexPath * indexPath) {
        if(!self.circleInfo)
        {
            return [RACSignal empty];
        }
        @strongify(self);
        MHSettingCircleViewModel *viewModel = [[MHSettingCircleViewModel alloc] initWithServices:self.services params:@{MHViewModelUtilKey:self.circleInfo}];
        [self.services pushViewModel:viewModel animated:YES];
        return [RACSignal empty];
    }];
    
    self.searchCommand = [[RACCommand alloc] initWithSignalBlock:^RACSignal *(NSIndexPath * indexPath) {
        @strongify(self);
        
        if(!self.circleInfo)
        {
            return [RACSignal empty];
        }
        MHSearchViewModel *viewModel = [[MHSearchViewModel alloc] initWithServices:self.services params:@{MHViewModelUtilKey:self.circleInfo}];
        [self.services pushViewModel:viewModel animated:YES];
        return [RACSignal empty];
    }];
    
//    self.prefersNavigationBarHidden = YES;
    
    self.fetchCircleInfoCommand =  [[RACCommand alloc] initWithSignalBlock:^RACSignal *(id input) {
       @strongify(self);
        void (^doNext)(MHCircleInfo *) = ^(MHCircleInfo *circleInfo){
          @strongify(self);
//           self.circleInfo = circleInfo;
            [AXAppDelegate sharedDelegate].currentCircleInfo = circleInfo;
           self.bottomInfoViewModel = [[MHCircleInfoBottomViewModel alloc] initWithServices:self.services params:@{MHViewModelUtilKey:circleInfo}];
        };
        return  [[self.services.client fetchCircleInfoWithCircleId:self.circielId] doNext:doNext];
    }];
    
    if(self.circleInfo)
    {
        self.bottomInfoViewModel = [[MHCircleInfoBottomViewModel alloc] initWithServices:self.services params:@{MHViewModelUtilKey:self.circleInfo}];
    }
    
    
}

-(void)dealloc
{
//    self.bottomInfoViewModel = nil;
}
@end
